'use strict';

const Service = require('egg').Service;

class UserService extends Service {
    async selectUser(num) {
        return await this.app.mysql.query('select * from userlist where num=?',[num])
    }
    //注册
    async registry(username,password,num){
        let role_id = 3,
            role_name = '学生';
        await this.app.mysql.query('insert into userlist (username,password,num,role_id,role_name) values (?,?,?,?,?)',[username,password,num,role_id,role_name])
    }

    //登录
    async login(num,password){
        return await  this.app.mysql.query('select * from userlist where num=? and password=?',[num,password])
    }

    //获取资源列表
    async resource(role_id){
        return await this.app.mysql.query(`select * from resouce_list where power like '%${role_id}%'`)
    }
}

module.exports = UserService;
